package va.radiomaria.gui;

import java.awt.Dimension;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;

public class ConsoleTabsPane extends JTabbedPane {

	private static final long serialVersionUID = 1L;

	HashMap<LoggerInstance, JTextArea> textAreas = new HashMap<LoggerInstance, JTextArea>(); 
	
	JTextArea allLog = new JTextArea();
	JTextArea p2pLog = new JTextArea();
	JTextArea miscLog = new JTextArea();
	JTextArea audioLog = new JTextArea();
	JTextArea recommenderLog = new JTextArea();
	
	public ConsoleTabsPane() {
		super();
		this.setBorder(null);
		textAreas.put(LoggerInstance.ALL, new JTextArea());
		textAreas.put(LoggerInstance.AUDIO, new JTextArea());
		textAreas.put(LoggerInstance.P2P, new JTextArea());
		textAreas.put(LoggerInstance.RECOMMENDER, new JTextArea());
		textAreas.put(LoggerInstance.MISC, new JTextArea());

		LoggerInstance[] loggersSortedByDisplayOrder = {LoggerInstance.ALL, LoggerInstance.P2P, LoggerInstance.AUDIO, LoggerInstance.RECOMMENDER, LoggerInstance.MISC};
		
		for (LoggerInstance loggerInstance: loggersSortedByDisplayOrder) {
			JTextArea textArea = textAreas.get(loggerInstance);
			textArea.setBackground(MainView.ACTIVE_BACKGROUND);
			textArea.setForeground(MainView.ACTIVE_FONT_COLOR);
			JScrollPane consoleScrollPane = new JScrollPane(textArea);
			consoleScrollPane.setPreferredSize(new Dimension(600, 150));
			consoleScrollPane.setBorder(null);
			this.addTab(loggerInstance.toString(), consoleScrollPane);
		}
		
		this.repaint();
	}
	
	public void update(Map<LoggerInstance, String> consoleTextMap) {
		for (LoggerInstance loggerInstance: consoleTextMap.keySet()) {
			JTextArea textArea = textAreas.get(loggerInstance);
			textArea.setText(consoleTextMap.get(loggerInstance));
		}
	}
}
